package com.bdyc.service.springImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.bdyc.controller.custom.ScategoryInfoPo;
import com.bdyc.dao.ScategoryInfoMapper;
import com.bdyc.service.spring.ScategoryInfoService;
@Service("scategoryInfoService")
public class ScategoryInfoServiceImpl implements ScategoryInfoService {

	@Autowired(required=true)
	@Qualifier("scategoryInfoMapper")
	private ScategoryInfoMapper scategoryInfoMapper;
	public List<ScategoryInfoPo> findCategoryInfo(Map<String, Object> map) {
		//设置limit起始索引 (currentPage-1)*pageSize
		Integer currentPage = (Integer)map.get("page");
		Integer pageSize  = (Integer)map.get("rows");
		//封装查询记录数map
		Integer count = scategoryInfoMapper.findScategoryInfoListCount(map);
		if(count >0){
			Integer index = count/pageSize;
			System.out.println(count%pageSize);
			Integer sum = count%pageSize==0?index:index +1;
			if(currentPage == null || currentPage <= 0){
				currentPage =1;
			}
			if(currentPage > sum ){
				currentPage=sum ;
			}
			map.put("currentPage",  (currentPage-1)*pageSize);
			map.put("pageSize", pageSize);
		}
		return scategoryInfoMapper.findScategoryInfoList(map);
	}

	public Integer findCategoryInfoCount(Map<String, Object> sendMap) {
		return scategoryInfoMapper.findScategoryInfoListCount(sendMap);
	}

}
